package javaweb.web;

import javaweb.pojo.User;
import javaweb.servlet.impl.UserServletImpl;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author shkstart
 * @creat ${YEAR-}-07-15 20:03
 */

public class LoginServlet extends HttpServlet {
    private UserServletImpl usl=new UserServletImpl();
    protected void doLoginPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        User user = usl.logUser(new User(username, password, null));
        if(user!=null){
            request.setAttribute("user",user);
request.getSession().setAttribute("user",user);
            //System.out.println("登录成功");

            request.getRequestDispatcher("/pages/user/login_success.jsp").forward(request,response);
        } else {
            request.setAttribute("msg","用户名或密码错误");
            request.setAttribute("username",username);
            request.getRequestDispatcher("/pages/user/login.jsp").forward(request,response);

        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
